package com.tandashi.springbootstudy01.study.thread;

public class MyThread extends Thread {
    private int i = 0;

    @Override
    public void run() {
        try {
            while (true) {
                i++;
                System.out.println("i=" + i);
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        /*long beginTime = System.currentTimeMillis();
        int count = 0;
        for (int i = 0; i < 500000; i++) {
            //Thread.yield();
            count = count + (i+1);
            //System.out.println("i = "+(i+1));
        }
        long endTime = System.currentTimeMillis();
        System.out.println("用时："+ (endTime-beginTime)+" ms");*/

    }

    public static void main(String[] args) {
        try {
            MyThread t1 = new MyThread();
            t1.setDaemon(true);
            t1.start();
            Thread.sleep(5000);
            System.out.println("我离开t1对象也不再打印了，也就是停止了");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
